package shared

import scala.math.BigDecimal.RoundingMode
import Implicits._

/**
 * Created by yz on 2019/4/24
 */

case class ResultData(cirrhosis: BigDecimal, lateFibrosis: BigDecimal, result: String)


object Shared {

  val userStr = "boost_user"
  val adminStr = "boost_admin"

  def calculateScore(resultData: ResultData) = {
    val cirrhosis = resultData.cirrhosis / 100
    val late = resultData.lateFibrosis / 100
    val early = 1 - late
    val score = resultData.result match {
      case "Early_Fibrosis" =>
        1 - early
      case "Late Fibrosis" =>
        0.5 + (1 - late) / 2
      case "Cirrhosis" =>
        0.75 + (cirrhosis - 0.5) / 2
    }
    score.toFixed(2)
  }

  def getResult(score: BigDecimal) = {
    score match {
      case x if x <= 0.5 => "早期肝纤维化风险"
      case x if x > 0.5 && x <= 0.75 => "晚期肝纤维化风险"
      case x if x > 0.75 => "肝硬化风险"
    }

  }

  def getDanger(score: BigDecimal) = {
    score match {
      case x if x <= 0.5 => "肝脏代谢指标综合分析出现异常，提示患有慢性肝病的可能性非常大。早期肝纤维化的可能性非常大。本结果仅供参考，肝纤维化、肝硬化程度请结合临床。"
      case x if x > 0.5 && x <= 0.75 => "肝脏代谢指标综合分析出现异常，提示患有慢性肝病的可能性非常大。晚期肝纤维化的可能性非常大。本结果仅供参考，肝纤维化、肝硬化程度请结合临床。"
      case x if x > 0.75 => "肝脏代谢指标综合分析出现异常，提示患有慢性肝病的可能性非常大。肝硬化的可能性非常大。本结果仅供参考，肝纤维化、肝硬化程度请结合临床。"
    }

  }


}
